package com.eling.elcms.cater.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;

import javax.persistence.*;

/**
 * 菜品
 *
 */
@Entity
@Table(name = "cate_dish",
		uniqueConstraints = {@UniqueConstraint(columnNames={"name","pkServicePoint"})})
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "iOrder"),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "servicepoint:servicePoint")})
public class Dish extends BaseModel {
	private static final long serialVersionUID = -3248358825927128266L;

	@Id
	@In
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	private Long pkDish;
	
	/** 菜品名称 **/
	@Column
	@Field
	private String name;
	
	/** 图片名称 **/
	@Column
	@Field
	private String imageName;
	
	/** 菜品类型 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkDishType")
	private DishType dishType;
	
	/** 序号 */
	@Column
	@Field
	private Integer iOrder;
	
	/** 备注 */
	@Column
	@Field
	private String remark;
	
	/** 服务点 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkServicePoint")
	private ServicePoint servicePoint;
	
	/** 状态*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private State state;
	
	@Version
	private Integer version;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum State {
		Sale("在售"),
		StopSale("停售");

		private String display;

		State(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkDish() {
		return pkDish;
	}

	public void setPkDish(Long pkDish) {
		this.pkDish = pkDish;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}

	public DishType getDishType() {
		return dishType;
	}

	public void setDishType(DishType dishType) {
		this.dishType = dishType;
	}

	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public Integer getiOrder() {
		return iOrder;
	}

	public void setiOrder(Integer iOrder) {
		this.iOrder = iOrder;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
